﻿package org.flixel.system.replay
{

    public class FrameRecord extends Object
    {
        public var frame:int;
        public var keys:Array;
        public var mouse:MouseRecord;

        public function FrameRecord()
        {
            this.frame = 0;
            this.keys = null;
            this.mouse = null;
            return;
        }// end function

        public function create(param1:Number, param2:Array = null, param3:MouseRecord = null) : FrameRecord
        {
            this.frame = param1;
            this.keys = param2;
            this.mouse = param3;
            return this;
        }// end function

        public function destroy() : void
        {
            this.keys = null;
            this.mouse = null;
            return;
        }// end function

        public function save() : String
        {
            var _loc_2:Object = null;
            var _loc_3:uint = 0;
            var _loc_4:uint = 0;
            var _loc_1:* = this.frame + "k";
            if (this.keys != null)
            {
                _loc_3 = 0;
                _loc_4 = this.keys.length;
                while (_loc_3 < _loc_4)
                {
                    
                    if (_loc_3 > 0)
                    {
                        _loc_1 = _loc_1 + ",";
                    }
                    _loc_2 = this.keys[_loc_3++];
                    _loc_1 = _loc_1 + (_loc_2.code + ":" + _loc_2.value);
                }
            }
            _loc_1 = _loc_1 + "m";
            if (this.mouse != null)
            {
                _loc_1 = _loc_1 + (this.mouse.x + "," + this.mouse.y + "," + this.mouse.button + "," + this.mouse.wheel);
            }
            return _loc_1;
        }// end function

        public function load(param1:String) : FrameRecord
        {
            var _loc_2:uint = 0;
            var _loc_3:uint = 0;
            var _loc_7:Array = null;
            var _loc_4:* = param1.split("k");
            this.frame = int(_loc_4[0] as String);
            _loc_4 = (_loc_4[1] as String).split("m");
            var _loc_5:* = _loc_4[0];
            var _loc_6:* = _loc_4[1];
            if (_loc_5.length > 0)
            {
                _loc_4 = _loc_5.split(",");
                _loc_2 = 0;
                _loc_3 = _loc_4.length;
                while (_loc_2 < _loc_3)
                {
                    
                    _loc_7 = (_loc_4[_loc_2++] as String).split(":");
                    if (_loc_7.length == 2)
                    {
                        if (this.keys == null)
                        {
                            this.keys = new Array();
                        }
                        this.keys.push({code:int(_loc_7[0] as String), value:int(_loc_7[1] as String)});
                    }
                }
            }
            if (_loc_6.length > 0)
            {
                _loc_4 = _loc_6.split(",");
                if (_loc_4.length >= 4)
                {
                    this.mouse = new MouseRecord(int(_loc_4[0] as String), int(_loc_4[1] as String), int(_loc_4[2] as String), int(_loc_4[3] as String));
                }
            }
            return this;
        }// end function

    }
}
